package com.szl.yeb.controller;


import com.szl.yeb.common.constant.MsgConstant;
import com.szl.yeb.entity.Admin;
import com.szl.yeb.common.R;
import com.szl.yeb.service.AdminRoleService;
import com.szl.yeb.service.AdminService;
import com.szl.yeb.utils.ResponseProcessor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 用户信息(Admin)表控制层
 *
 * @author szl
 * @since 2022-08-24 16:21:21
 */
@Api(tags = "操作员管理接口(admin)")
@RestController
@RequestMapping("system/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private AdminRoleService adminRoleService;

    @ApiOperation("查询所有其他操作员及其角色信息")
    @GetMapping("/")
    public R<Object> selectOtherAdminsWithRoles( String keyword) {
        return R.obj(adminService.selectOtherAdminsWithRoles(keyword));
    }

    @ApiOperation("修改操作员角色")
    @PutMapping("/role")
    public R<Object> updateAdminRole(String adminId, @RequestBody List<Integer> rids) {
        return ResponseProcessor.getResWithMsg(adminRoleService.updateAdminRole(adminId,rids), MsgConstant.UPDATE);
    }

    @ApiOperation("更新操作员信息")
    @PutMapping("/")
    public R<Object> updateAdmin(@RequestBody Admin admin) {
        return ResponseProcessor.getResWithMsg(adminService.updateById(admin), MsgConstant.UPDATE);
    }

    @ApiOperation("删除操作员信息")
    @DeleteMapping("/{id}")
    public R<Object> updateAdmin(@PathVariable("id") Integer adminId) {
        return ResponseProcessor.getResWithMsg(adminService.removeById(adminId), MsgConstant.DELETE);
    }
}

